<?php
set_time_limit( 99 );
date_default_timezone_set('Asia/Shanghai');
header("charset=utf8");
$beginTime = microtime(true);
?><html>
<head>
	<meta charset="utf-8">
	<title>change_top_png</title>
</head>
<body style="text-align:center;">

<?php
// 允许上传的图片后缀
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
//echo $_FILES["file"]["size"];
$extension = end($temp);     // 获取文件后缀名
if (
	(($_FILES["file"]["type"] == "image/gif")
	|| ($_FILES["file"]["type"] == "image/jpeg")
	|| ($_FILES["file"]["type"] == "image/jpg")
	|| ($_FILES["file"]["type"] == "image/pjpeg")
	|| ($_FILES["file"]["type"] == "image/x-png")
	|| ($_FILES["file"]["type"] == "image/png"))
	&& in_array($extension, $allowedExts)
)
{
	if ($_FILES["file"]["error"] > 0)
	{
		echo '<script>alert("'.$_FILES["file"]["error"].'");</script>';
//		echo "error : " . $_FILES["file"]["error"] . "<br>";
	}
	else
	{
//		echo "file name : " . $_FILES["file"]["name"] . "<br>";
//		echo "file type : " . $_FILES["file"]["type"] . "<br>";
//		echo "file size : " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
//		echo "file temp save path : " . $_FILES["file"]["tmp_name"] . "<br>";
		// 判断当期目录下的 upload 目录是否存在该文件
		// 如果没有 upload 目录，你需要创建它，upload 目录权限为 777
//		if (file_exists("upload/" . $_FILES["file"]["name"]))
//		{
//			echo $_FILES["file"]["name"] . " file exists ";
//		}
//		else
//		{
			// 如果 upload 目录不存在该文件则将文件上传到 upload 目录下
			// move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"])
			if( move_uploaded_file($_FILES["file"]["tmp_name"], "wall/style/spring/images/top2.png") ){
				echo '<script>alert("上传成功.");</script>';
			}else{
				echo '<script>alert("上传失败,可能服务器没有权限.");</script>';
			}
//			echo "file save to : " . "upload/" . $_FILES["file"]["name"];
//		}
	}
	echo '<script>window.history.back();</script>';
	exit();
}
?>
<form action="?c=Save" method="post" enctype="multipart/form-data">
	<p>
		<input type="file" name="file" id="file" />
	</p>
	<p>
		<input type="submit" name="submit" value="提交上传">
		<a href="" target="_blank">查看图片</a>(要刷新查看)
	</p>
	<p>
		<label for="file">提示：请上传最多 1294 x 180 (或相同比率)像素的png格式图片</label>
	</p>
</form>
</body>
</html>